package com.aaa.three.util;

import com.aaa.three.entity.TableDate;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @PACKAGE_NAME: com.aaa.three.util
 * @NAME: DateUtil
 * @USER: Tprairie
 * @DATE: 2022/2/19
 * @PROJECT_NAME: three
 */
public class DateUtil {
    public static TableDate listTitle(){
        TableDate tableDate = new TableDate();
        Field[] declaredFields = tableDate.getClass().getDeclaredFields();
        for (int i = 0; i < declaredFields.length; i++) {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            Calendar c = Calendar.getInstance();
            c.setTime(new Date());
            c.add(Calendar.DATE,+i);
            Date d = c.getTime();
            String day = simpleDateFormat.format(d);
            String name = declaredFields[i].getName();
            String methodName=name.substring(0,1).toUpperCase()+name.substring(1);
            try {
                Method setMethod= tableDate.getClass().getMethod("set" + methodName,String.class);
                setMethod.invoke(tableDate,day);
            } catch (Exception e) {
                e.printStackTrace();
            }

        }
        return tableDate;
    }
}
